<template>
	<view class="notice-container">
		<view class="notice-item" v-for="(item,index) in noticeList" :key="item.id">
			<view class="item-left" @click="toNoticeDetail(item.id)">
				<view class="title">{{item.noticeTitle}}</view>
				<view class="time">发布时间：{{item.creationTime}}</view>
				<view class="author">发布人：{{item.founder}}</view>
				<view class="stauts">
				<u-tag :text="item.state==1?'发布中':'暂停发布'" :type="item.state===1?'success':'error'">
				</u-tag>
				</view>
			</view>
			<view class="item-right">
				<u-image :src="'http://1.12.48.84:8283'+'/neuedu-admin'+item.imagersUpload" width="100" height="100" ></u-image>
			</view>
			
		</view>
		
				<uni-fab ref="fab" horizontal="right" vertical="bottom" direction="horizontal" @fabClick="toAddNotice"/>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				noticeList:[],
				pageNum:1,
				pageSize:10,
				total:0
			};
		},
		onLoad() {
			var _this = this
			// setTimeout(function () {
			//  uni.stopPullDownRefresh();
			// 	var _this = this
			// 		_this.getNoticeList()
			// }, 3000);
			uni.$on('addNotice',function(data){
					
				_this.getNoticeList()
					// this.visitSoureList.push(data)
				});
				uni.startPullDownRefresh();
				_this.getNoticeList()
		},
		onPullDownRefresh() {
					console.log('refresh');
				// setTimeout(function () {
				// 	uni.stopPullDownRefresh();
				// }, 2000);
				this.pageNum=1
				this.noticeList=[]
				this.getNoticeList()
			},
			onReachBottom() {
				
				this.pageNum++
				console.log('pagenum:',this.pageNum)
				if(this.pageNum*this.pageSize>this.total){
					uni.$u.toast('到底了')
				}else{
					this.getNoticeList()
				}
				
			},
		methods:{
			toAddNotice(){
				uni.navigateTo({
					url:'/pages/notice/addNotice'
				})
			},
			toNoticeDetail(id){
				uni.navigateTo({
					url:'/pages/notice/noticeDetail?id='+id
				})
			},
			getNoticeList() {
			
				uni.request({
					url: 'https://www.gzzyue.com/prod-api/system/campusNotice/list?pageNum='+this.pageNum+'&pageSize='+this.pageSize,
					method: 'GET',
					header: {
						'Authorization': uni.getStorageSync("token") //自定义请求头信息
					},
					success: (res) => {
						console.log('noticeList:', res);
						
						if (res.statusCode == 200) {
							if (res.data.code == 200) {
								// this.noticeList=res.data.rows
								for (let s of res.data.rows) {
									this.noticeList.push(s)
								}
								
								this.total=res.data.total
								// setTimeout(function () {
								// 	uni.stopPullDownRefresh();
								// }, 3000);
								uni.stopPullDownRefresh();
							} else if (res.data.code == 500) {
								uni.$u.toast(res.data.msg)
							} else {
								uni.$u.toast('系统服务异常，请联系管理员！')
							}
						} else {
							uni.$u.toast('系统服务异常，请联系管理员！')
						}
					},
					fail: (errors) => {
						console.log('errors:', errors);
						uni.$u.toast('服务器错误，请联系管理员！')
					},
				});
			}
		}
		
	}
</script>

<style lang="scss" scoped>
.notice-container{
	padding: 10px;
	.notice-item{
		display: flex;
		flex-direction: row;
		margin-top: 10px;
		padding: 8px;
		border: 1px solid #000;
		border-radius: 8px;
		align-items: center;
		justify-content: space-between;
		.item-left{
			.time{
				margin-top: 5px;
				font-size: 13px;
				color: orange;
			}
			.author{
				margin-top: 5px;
				font-size: 13px;
				color: orange;
			}
			.stauts{
				width: 75px;
				margin-top: 5px;
			}
		}
		.item-right{
			margin-top: 18px;
			// margin-top: -10px;
		}
	}
}
</style>
